package com.pmsystem.service;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pmsystem.dao.FreeCarMapper;
import com.pmsystem.dao.UserMapper;

import com.pmsystem.pojo.User;
import com.pmsystem.pojo.UserExample;
import com.pmsystem.pojo.UserExample.Criteria;
import com.pmsystem.util.MD5;

@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;
	@Autowired
	private FreeCarMapper freeCarMapper;

	
	/**
	 * 
	 * <p>Title: login</p >  
	 * <p>Description: 业主登陆</p >  
	 * @author 泽强
	 * @param username
	 * @param password
	 * @return
	 */
	public User login(String username, String password) {
		String encodePwd = MD5.MD5Eencryption(password, username);

		if(encodePwd==null)
			return null;
		return userMapper.login(username,encodePwd);

	}


	/**
	 * 
	 * <p>Title: update</p >  
	 * <p>Description: 业主更改信息</p >  
	 * @author 泽强
	 * @param user
	 * @return
	 */
	public boolean update(User user) {
		int flag=userMapper.updateByPrimaryKeySelective(user);	
		return flag==1?true:false;
	}


	/**  
	 * <p>Title: regist</p >  
	 * <p>Description:业主注册</p >
	 * @author 魏家洛
	 * @param user
	 * @return  
	 */  
	public boolean regist(User user) {
		String encodePwd = MD5.MD5Eencryption(user.getUserPassword(), user.getUserName());
		if(encodePwd==null)
			return false;
		user.setUserPassword(encodePwd);
		return (userMapper.insertUser(user)==1);
	}
	
	
	/**
	 * 
	 * <p>Title: showUser</p>  
	 * <p>Description:用户表全查询 </p>  
	 * @author 树昌
	 * @return
	 */
	public List<User> showUser() {
		
		UserExample userExample = new UserExample();
		Criteria criteria = userExample.createCriteria();
		criteria.andEnableNotEqualTo((byte) 0);
		return userMapper.selectByExample(userExample);
	}
}
